<?php


namespace App\controller;


use App\Redis;

class RegisterController extends BaseController
{

    const Key = 'connect_fd';

    /**
     * returnPackData
     * @return array
     * date:2021/12/24
     * time:13:43
     * auth：xyc
     */
    public function returnPackData()
    {
        $this->bindFd();
        return [];
    }

    /**
     * bindFd
     * date:2021/12/22
     * time:15:43
     * auth：xyc
     */
    private function bindFd()
    {
        foreach ($this->table as $row) {
            if ($row['printer'] == $this->content) {
                throw new \RuntimeException("打印机已经存在!");
            }
        }

        if (!$this->table->set(strval($this->fd), [
            'time' => time(),
            'printer' => $this->content,
        ])) {
            throw new \RuntimeException("打印机注册失败!");
        }

    }


}